
<html>
<head>
<meta charset="UTF-8">
<title>表模型字段新增</title>
<link href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
<link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
<script src="../../ffres/dict/all.js"></script>
<a href="" target="_blank" id="commonLink" name="commonLink"></a>
<script type="text/javascript">


	$(function() {

		$('#dg').datagrid({
			onDblClickRow : function(rowIndex) {
				doRef();
			}
		});
		
		$('#fieldCode').textbox('textbox').bind('keydown', function() {
			var e = event || window.event || arguments.callee.caller.arguments[0];
			if (event.keyCode == 13 || event.keyCode == 9) {
				$("#itemCode").textbox("setValue", $('#fieldCode').val());
				doQuery();
			} else {
				//$("#itemCode").textbox("setValue",e && event.keyCode);
			}
		});
		
		/*$('#fieldCode').textbox('textbox').bind('blur', function() {
			var fieldCode = $('#fieldCode').val();
			if(!(fieldCode==null||fieldCode==undefined||fieldCode=="")) {
				$("#itemCode").textbox("setValue", fieldCode);
				doQuery();
			}
		});*/

		$('#isPk').change(
			function isPkChange(event){
				if ($('#isPk').prop("checked")) {
					$('#isAllowNull').prop("checked", false);
					$('#isAllowNull').attr("disabled", true);
				} else {
					$('#isAllowNull').attr("disabled", false);
				}

			}
		);
		
		$('#objectId').val($.getUrlParam('objectId'));

	});

	function doQuery() {
		$('#dg').datagrid('options').url = '../../api/dict/item/infos?'
				+ $('#searchForm').serialize();
		$('#dg').datagrid('reload');
	}

	function doRef() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$('#ff').form('clear');
			$('#ff').form('load', {
				fieldCode : row.itemCode,
				fieldName : row.itemName,
				fieldDesc : row.itemRemarks,
				itemId : row.itemId,
				objectId : $.getUrlParam('objectId'),
				fieldType : row.itemDataType,
				fieldLength : row.itemDataLength,
				fieldPrecision : row.itemDataPrecision,
				dictId : row.dictId,
				fieldOption : row.dictCode
			});
		} else {
			$.messager.alert('提示', '请选择要引用的数据条目！');
		}
	}

	function doAdd(){
		JLEUtil.createModalWin('新增', 'DictItemInfoAdd.html');
	}
	

	function doView(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('查看数据条目','DictItemInfoView.html?' + 'itemId=' + row.itemId);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function submitForm() {
		if (!$('#ff').form('validate'))
			return;
		var jsonData = $("#ff").serializeJson();
		jsonData.isAllowNull = $('#isAllowNull').prop("checked") ? "on" : "";
		$.restfulPostJson('../../api/model/table/field', jsonData, function(data) {
			window.parent.reloadList();
		});
	};
	
	function closeForm() {
		window.parent.JLEUtil.closewin();
	}
	
	function reloadList(){
		JLEUtil.closewin();
	}
</script>
</head>
<body class="easyui-layout">
<div class="easyui-layout" title="" style="width:100%;height:100%;padding:0px;">
	<div data-options="region:'center',split:false,collapsible:false" title="字段属性" style="width:35%;">
	    <form id="ff" method="post">
	    	<table width="100%" cellspacing="1" cellpadding="3" border="0">
	    		<tr>
	    			<td width="25%" align="right">字段代码：</td>
	    			<td width="75%">
	    				<input class="easyui-textbox" type="text" name="fieldCode" id="fieldCode" data-options="required:true" style="width:230px;height:25px;"/>
	    				<input type="hidden" name="itemId" id="itemId"/>
	    				<input type="hidden" name="dictId" id="dictId"/>
	    				<input type="hidden" name="objectId" id="objectId"/>
	    			</td>
	    		</tr>
	    		<tr>
	    			<td width="25%" align="right">字段名称：</td>
	    			<td width="75%"><input class="easyui-textbox" type="text" name="fieldName" id="fieldName" data-options="required:true" style="width:230px;height:25px;"/></td>
	    		</tr>
	    		<tr>
	    			<td width="25%" align="right">字段设置：</td>
	    			<td width="75%"><input type="checkbox" name="isPk" id="isPk" data-options="required:true">主键</input>
	    			&nbsp;&nbsp;
	    			<input type="checkbox" name="isAllowNull" id="isAllowNull" data-options="required:true">允许为空</input></td>
	    		</tr>
	    		<tr>
	    			<td width="25%" align="right">数据类型：</td>
	    			<td width="75%">
	    				<select class="easyui-combobox"  id="fieldType" name="fieldType" style="width:230px;height:25px" data-options="editable:false,valueField:'enname',textField:'cnname',data:PUB_DATA_TYPE"></select>
	    			</td>	    			
	    		</tr>  		
	    		<tr>
	    			<td width="25%" align="right">数据长度：</td>
	    			<td width="75%"><input class="easyui-numberbox"  type="text" id="fieldLength" name="fieldLength" data-options="required:true" style="width:230px;height:25px;"></input></td>
	    		</tr>
	    		<tr>
	    			<td width="25%" align="right">数据精度：</td>
	    			<td width="75%"><input class="easyui-numberbox"  type="text" id="fieldPrecision" name="fieldPrecision" style="width:230px;height:25px;" value="0"></input></td>	    			
	    		</tr>
	    		<tr>
	    			<td width="25%" align="right">数据选项：</td>
	    			<td width="75%"><input class="easyui-textbox"  id="fieldOption" name="fieldOption" style="width:230px;height:25px;"></td>
	    		</tr>
	    		<tr>
					<td width="25%" align="right" valign="top">字段备注：</td>
	    			<td width="75%" ><input class="easyui-textbox" name="fieldDesc" id="fieldDesc" data-options="multiline:true" style="height:60px;width:230px;"/></td>	    			
	    		</tr>		    			    			    		
	    	</table>
	    </form>		
	</div>
	<div data-options="region:'east',split:false,collapsible:false" title="可引用的数据条目" style="width:65%;">
		<table id="dg" class="easyui-datagrid" title=""
			style="width: 100%; height: 100%"
			data-options="singleSelect:true,collapsible:true,method:'post'"
			title="Load Data" rownumbers="true" pagination="true"
			pageSize="20" toolbar="#tb">
			<thead>
				<tr>					
					<th data-options="field:'itemCode'" width="20%">条目代码</th>
					<th data-options="field:'itemName'" width="20%">条目名称</th>				
					<th data-options="field:'itemDataType'" width="20%" formatter="formatter_PUB_DATA_TYPE">数据类型</th>
					<th data-options="field:'itemDataLength'" width="10%">数据长度</th>
					<th data-options="field:'itemDataPrecision'" width="10%">数据精度</th>
					<th data-options="field:'dictCode'" width="20%">数据选项</th>
					<th data-options="field:'refCount'" width="12%">引用次数</th>		
					<th data-options="field:'createUser'" width="12%" >创建者</th>
					<th data-options="field:'createTime'" width="15%">创建时间</th>					
				</tr>
			</thead>
		</table>
	</div>
	<div data-options="region:'south',split:false" style="height:50px;text-align:center;padding:10px">
		    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">&nbsp;保&nbsp;存&nbsp;</a>&nbsp;
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeForm()">&nbsp;关&nbsp;闭&nbsp;</a>
	    	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	</div>
</div>
<div id="tb" style="padding:0px">
	<div id="selectPanel"  class='easyui-panel'title="输入查询条件" style="margin:0 0 5px 0;height:36px" data-options="border:true,fit:false,dosize:true,noheader:true,collapsible:false,minimizable:false,maximizable:false,closable:false,collapsed:false,minimized:false,maximized:false,closed:false,cache:true,loadingMessage:'loading'">
		<form id="searchForm">
			<table>
				<tr>
					<td>&nbsp;条目代码：</td>
					<td><input class="easyui-textbox" type="text" name="itemCode" id="itemCode" style="height:25px;"/></td>
					<td>&nbsp;条目名称：</td>
					<td><input class="easyui-textbox" type="text" name="itemName" id="itemName" style="height:25px;"/></td>
					<td><a class="easyui-linkbutton" id="btnQuery" onclick="doQuery();">查找</a></td>
					<td><a class="easyui-linkbutton" id="btnClear" href="javascript:void(0);" onclick="JLEUtil.clearForm('searchForm');">清空</a></td>
				</tr>
			</table>
		</form>
	</div>
	<div style="margin-bottom:1px">
		<a href="javascript:doRef();" class="easyui-linkbutton" iconCls="icon-ok" plain="true">引用条目</a>
		<a href="javascript:doAdd();" class="easyui-linkbutton" iconCls="icon-add" plain="true">创建条目</a>
		<a href="javascript:doView();" class="easyui-linkbutton" iconCls="icon-ok" plain="true">查看条目</a>
	</div>
</div>
</body>
</html>
